package com.xuecheng.content.api;

import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.content.model.dto.CourseTeacherDTO;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseBaseInfoService;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author woldier
 * @version 1.0
 * @description 课程教师相关接口
 * @date 2023/3/8 8:52
 **/
@Api(value = "课程教师管理接口",tags = "课程教师管理接口")
@RestController
@RequestMapping("/courseTeacher")
@RequiredArgsConstructor
public class CourseTeacherController {

    private final CourseTeacherService courseTeacherService;
    private final CourseBaseInfoService courseBaseInfoService;

    /**
     * @description 根据课程id查询教师
     * @param courseId  课程id
     * @return java.util.List<com.xuecheng.content.model.po.CourseTeacher>
     * @author: woldier
     * @date: 2023/3/8 8:55
     */
    @ApiOperation("根据课程id查询课程教师信息")
    @GetMapping("/list/{courseId}")
    public List<CourseTeacher> list(@PathVariable @NotNull(message = "课程id不能为空") Long courseId){
        List<CourseTeacher> result = courseTeacherService.getIdByCourseTeacherList(courseId);
        return result;
    }

    /**
     * 添加,修改课程教师信息
     * @param courseTeacherDTO
     * @return
     */
    @ApiOperation("添加修改课程教师信息")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course')")
    @PostMapping
    public CourseTeacher saveOrUpdateTeacher(@RequestBody CourseTeacherDTO courseTeacherDTO){
        CourseTeacher courseTeacher = courseTeacherService.saveAndUpdate(courseTeacherDTO);
        return courseTeacher;
    }

    /**
     * 删除课程教师信息
     * @param
     * @return
     */
    @ApiOperation("删除课程教师信息")
//    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course')")
    @DeleteMapping("/course/{courseId}/{id}")
    public void deleteById(@PathVariable Long courseId, @PathVariable Long id){
        courseTeacherService.deleteCourseTeacher(courseId,id);
    }
}
